/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.processing.prediction;

import aiaudio.lastfm.hbase.CannotCreateTableException;
import aiaudio.processing.MainTableGroup;
import aiaudio.processing.base.AlgorithmParameters;
import aiaudio.processing.base.TimeMeasuredAlgorithm;
import aiaudio.processing.prediction.recalc.UserRatingsCalculationAlgorithm;
import aiaudio.processing.prediction.recset.RecomendationSetCreationAlgorithm;
import aiaudio.processing.prediction.top.MakeRecommendationAlgorithm;
import java.io.IOException;

/**
 *
 * @author nastya
 */
public class MakePredictionAlgorithm extends TimeMeasuredAlgorithm<MakePredictionAlgorithmParameters> {

    public MakePredictionAlgorithm(MainTableGroup mainTableGroup) {
        super(mainTableGroup, "make prediction");
    }

    @Override
    protected void removeTemporaryTables() {
    }

    @Override
    protected void createTemporaryTables() throws IOException {
    }

    @Override
    protected void process() throws IOException, CannotCreateTableException, InterruptedException, ClassNotFoundException {
        createRecommendationSet();
        calculateRatings();
        makeRecommendation();
    }

    private void makeRecommendation() throws IOException, ClassNotFoundException, CannotCreateTableException, InterruptedException {
        MakeRecommendationAlgorithm algorithm = new MakeRecommendationAlgorithm(mainTableGroup);
        algorithm.setMaxPositionCount(parameters.getMaxPositionCount());
        algorithm.start();
    }

    private void calculateRatings() throws InterruptedException, ClassNotFoundException, IOException, CannotCreateTableException {
        UserRatingsCalculationAlgorithm algorithm = new UserRatingsCalculationAlgorithm(mainTableGroup);
        algorithm.start();
    }

    private void createRecommendationSet() throws IOException, CannotCreateTableException, InterruptedException, ClassNotFoundException {
        RecomendationSetCreationAlgorithm algorithm = new RecomendationSetCreationAlgorithm(mainTableGroup);
        algorithm.prepare();
        algorithm.start();
    }

    @Override
    protected void measureAll() throws IOException {
    }

    @Override
    protected void writeParameters(MakePredictionAlgorithmParameters parameters) throws IOException {
    }
}
